﻿using HighThroughput.Common;
using OSSUtility;
using OSSUtility.DB;
using Ozone.Common;
using Ozone.Help;
using Ozone.Models;
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ozone.DAL
{

    public class DataHisDAL
    {
        public DataHisDAL()
        {

        }

        public SQLiteDataReader getList(string sWhere, string orderBy = "")
        {
            SqliteModel sqlModel = new SqliteModel(globalVar.g_connDBStr);
            string strSql = " select  * from DataHis where 1=1 " + sWhere
                                + orderBy;
            SQLiteDataReader reader = sqlModel.ExecuteDataTable(strSql);
            return reader;
        }

        public void Add(DataHisItem module)
        {
            try
            {
                string str = " insert into  DataHis(" +
                                                     "FLineNum," +
                                                     "FJson," +
                                                     "FDate" +
                                                     ") " +
                   "   values( " +
                            module.FLineNum + "" +
                           ",'" + module.FJson + "'" +
                           ",'" + module.FDate + "'" +

                           ")"
                   ;

                SqliteModel sqlModel = new SqliteModel(globalVar.g_connDBStr);
                sqlModel.ExecuteNonQuery(str);
            }
            catch (Exception ex)
            {
                string methodName = LogHelper.LogErrorTitle();
                Log.writeLog(methodName, ex.Message);
            }
        }

        public bool Update(DataHisItem module)
        {
            try
            {
                string str = " update DataHis set " +
                                                       "FLineNum=" + module.FLineNum + "," +
                                                       "FJson='" + module.FJson + "'," +
                                                       " where FID=" + module.FID + ""
                                                       ;

                SqliteModel sqlModel = new SqliteModel(globalVar.g_connDBStr);
                sqlModel.ExecuteNonQuery(str);
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public void Delete(string sWhere)
        {
            try
            {
                string str = " delete  from DataHis where 1=1 " + sWhere;

                SqliteModel sqlModel = new SqliteModel(globalVar.g_connDBStr);
                sqlModel.ExecuteNonQuery(str);
            }
            catch (Exception ex)
            {
            }
        }
    }
}
